package ratelimit.distribute;



import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: Fazhan.Qiao
 * @Date: 2019/5/20 10:05
 * @Description:  测试限流
 */
@RestController
public class TestController {

   //测试限流1
    @RateLimiter(base = RateLimiter.Base.General, permits = 10, timeUnit = TimeUnit.SECONDS)
    @RequestMapping(value="/test1", method = RequestMethod.POST)
    public String test1() {
        return "test1!";
    }

    //测试限流11
    @RateLimiter(base = RateLimiter.Base.General, permits = 10, timeUnit = TimeUnit.MINUTES)
    @RequestMapping(value="/test11", method = RequestMethod.POST)
    public String test11() {
        return "test1!";
    }

    //注意请求头包含相应的值
    //测试限流
    @RateLimiter(base = RateLimiter.Base.IP, path="/test2", permits = 10, timeUnit = TimeUnit.SECONDS)
    @RequestMapping(value="/test2/{id}", method = RequestMethod.POST)
    public String test2(@PathVariable(value = "id")Long id) {
        return "test2! " + id;
    }

    //注意请求头包含相应的值
    //测试限流22
    @RateLimiter(base = RateLimiter.Base.IP, path="/test22", permits = 10, timeUnit = TimeUnit.MINUTES)
    @RequestMapping(value="/test22/{id}", method = RequestMethod.POST)
    public String test22(@PathVariable(value = "id")Long id) {
        return "test2! " + id;
    }


    //注意请求头包含UserToken
    //测试限流3
    @RateLimiter(base = RateLimiter.Base.User, path="/test3", permits =10, timeUnit = TimeUnit.SECONDS)
    @RequestMapping(value="/test3/{id}", method = RequestMethod.POST)
    public String test3(@PathVariable(value = "id")Long id) {
        return "test3! " + id;
    }

    //注意请求头包含UserToken
    //测试限流33
    @RateLimiter(base = RateLimiter.Base.User, path="/test33", permits = 10, timeUnit = TimeUnit.MINUTES)
    @RequestMapping(value="/test33/{id}", method = RequestMethod.POST)
    public String test33(@PathVariable(value = "id")Long id) {
        return "test3! " + id;
    }
}
